package com.books.controller.order;

import com.books.model.bo.Result;
import com.books.model.entity.address.Receiving_address;
import com.books.model.entity.shopping.ShoppingCar;
import com.books.service.address.IAddressService;
import com.books.service.admin.IAdminService;
import com.books.service.shoppingcar.IShoppingCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;


/**
 * @author ZhouRui
 * @title: 码上就来
 * @projectName cbstore-spring-boot
 * @description: TODO
 * @date 2021/10/919:29
 */
@Controller
@RequestMapping("/orderindex")
public class OrderDetailController {
    @Autowired(required = false)
    private IShoppingCarService shoppingCarService;

    @Autowired(required = false)
    private ShoppingCar shoppingCar;

    @Autowired(required = false)
    private IAddressService addressService;


    @Autowired(required = false)
    private IAdminService adminService;

    @GetMapping("/orderdetail")
    public String toindex(){
        return "order/orderdetail";
    }


    @GetMapping("/add")
    @ResponseBody
    public Result addo(HttpServletRequest request,String  cid){
        String [] str=cid.split(",");
        HttpSession session=request.getSession();
        List<ShoppingCar> car=new ArrayList<>();
        for (int i = 0; i < str.length; i++) {
            shoppingCar=shoppingCarService.findById(Integer.valueOf(str[i]));
            car.add(shoppingCar);
        }
        session.setAttribute("carlist",car);
        return new Result("200","已选择商品");
    }

    @GetMapping("/address")
    @ResponseBody
    public Result address(HttpServletRequest request, Integer id){
        HttpSession session=request.getSession();
        List<Receiving_address> addressList=addressService.findAllByPid(id);
        session.setAttribute("addresslist",addressList);
        return new Result("200","地址添加成功");
    }

    @GetMapping("/vipName")
    @ResponseBody String vipName(Integer vipId){
        String vipName = adminService.findByVipId(vipId).getVipName();
        return vipName;
    }
}
